define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'fittings/aftersale/index' + location.search,
                    add_url: 'fittings/aftersale/add',
                    // edit_url: 'fittings/aftersale/edit',
                    // del_url: 'fittings/aftersale/del',
                    multi_url: 'fittings/aftersale/multi',
                    import_url: 'fittings/aftersale/import',
                    table: 'fittings_order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        { checkbox: true },
                        { field: 'id', title: __('Id') },
                        { field: 'sn', title: __('Sn'), operate: 'LIKE' },
                        { field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE' },
                        { field: 'title', title: __('Title'), operate: 'LIKE' },
                        { field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image },
                        { field: 'pay_price', title: __('Pay_price'), operate: 'BETWEEN' },
                        { field: 'sale_status', title: __('Sale_status'), searchList: { "0": __('Sale_status 0'), "1": __('Sale_status 1'), "2": __('Sale_status 2') }, formatter: Table.api.formatter.status },
                        { field: 'refund_status', title: __('Refund_status'), searchList: { "0": __('Refund_status 0'), "1": __('Refund_status 1'), "2": __('Refund_status 2') }, formatter: Table.api.formatter.status },
                        { field: 'refund_express', title: __('Refund_express'), operate: 'LIKE' },
                        { field: 'refund_express_sn', title: __('Refund_express_sn'), operate: 'LIKE' },
                        { field: 'refund_num', title: __('Refund_num') },
                        { field: 'refund_price', title: __('Refund_price'), operate: 'BETWEEN' },
                        { field: 'refund_images', title: __('Refund_images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images },
                        { field: 'refund_reason', title: __('Refund_reason'), operate: 'LIKE' },
                        {
                            field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'confirmreturn',
                                    title: '退款',
                                    text: '退款',
                                    classname: 'btn btn-primary btn-xs btn-view btn-dialog',
                                    url: 'fittings/order/confirmreturn',//接口地址 控制器名/方法名
                                    visible: function (row) {//判断显示隐藏 只有状态为待审核时展示操作按钮
                                        if (row.refund_status == '1') {
                                            return true;//显示
                                        } else {
                                            return false;//隐藏
                                        }
                                    },
                                },
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        confirmreturn: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
